<!DOCTYPE html>
<html lang="en">

	<head>
		<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
		<meta charset="UTF-8">
		<title>注册</title>
		<link rel="stylesheet" href="css/weui.css">
		<!--<link rel="stylesheet" href="css/jquery-weui.min.css">-->
		<link rel="stylesheet" href="css/map.css">
		<style type="text/css">
			.text_center {
				text-align: center;
			}
			
			.register_mail {
				height: 45px;
			}
		</style>
	</head>

	<body>
		<div class="add"></div>
		<div class="weui-cells weui-cells_form">
			<div class="weui-cell weui-cell_vcode">
				<div class="weui-cell__hd">
					<!--<label class="weui-label">手机号</label>-->
				</div>
				<div class="weui-cell__bd">
					<input class="weui-input register_mail text_center" id="register_email" type="text" onblur="yzEmail(this)" placeholder="请输入邮箱">
				</div>
			</div>

			<!--输入验证码-->
			<!--<div class="weui-cell">
        <div class="weui-cell__bd">
            <input class="weui-input register_yzm" type="number" pattern="[0-9]*" placeholder="请输入验证码">
        </div>
        <div class="weui-cell__ft">
            <i class="weui-icon-safe-success"></i>
        </div>
    </div>-->
			<div class="weui-cell">
				<!--<div class="weui-cell__hd"><label class="weui-label">密码</label></div>-->
				<div class="weui-cell__bd">
					<input class="weui-input register_pwd text_center" id="register_pwd" type="password" placeholder="请输入不少于8字密码">
				</div>
				<div class="weui-cell__ft">
					<i class="weui-icon-safe-success"></i>
				</div>
			</div>
			<div class="weui-cell">
				<!--<div class="weui-cell__hd"><label class="weui-label">再次输入</label></div>-->
				<div class="weui-cell__bd">
					<input class="weui-input register_rpwd text_center" id="register_rpwd" type="password" placeholder="请再次输入密码">
				</div>
				<div class="weui-cell__ft">
					<i class="weui-icon-safe-success"></i>
				</div>
			</div>
			<a class="weui-btn weui-btn_plain-primary register_click">确定注册</a>
			<a href="login.html" class="weui-btn weui-btn_plain-primary">返回登录</a>
		</div>
		<script src="js/av-min-2.1.2.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/jquery-2.1.4.js"></script>
		<script src="js/fastclick.js"></script>
		<script src="js/register.js"></script>
		<script>
			$(function() {
				FastClick.attach(document.body);
			});
			//接入leanCloud注册邮箱
			var isreg = false;
			window.onload = function() {
				var APP_ID = 'hN1kSQf2DQ9awcJmwEmIIdVo-gzGzoHsz';
				var APP_KEY = 'aHCVjhhcyeerTEsKObkGSyd6';
				AV.init({
					appId: APP_ID,
					appKey: APP_KEY
				});
			}

			function yzEmail(t) {
				//正则表达式
				var ret = /^([A-z0-9_\.\-])+\@(([A-z0-9\-])+\.)+([A-z0-9]{2,4})+$/; //验证邮箱
				if (!ret.test($("#register_email").val())) {
					alert('请正确输入邮箱')
				}
				AV.User.requestEmailVerify(t.value).then(function(result) {
					isreg = false;
					alert("该邮箱已经被注册")
				}, function(error) {
					isreg = true;
				});
			}
			$(".register_click").click(function() {
				if (isreg) {
					var register_email = $("#register_email").val();
					var register_pwd = $("#register_pwd").val();
					var register_rpwd = $("#register_rpwd").val();
					if (register_pwd != register_rpwd) {
						alert("两次输入密码不同，请重新输入")
					} else {
						// 新建 AVUser 对象实例
						var user = new AV.User();
						// 设置用户名
						user.setUsername(register_email);
						// 设置密码
						user.setPassword(register_pwd);
						// 设置邮箱 
						user.setEmail(register_email);
						user.signUp().then(function(loginedUser) {
							alert("注册成功");
							location.href = 'login.html';
							//						
						}, function(error) {
							console.log(error)
						});
					}
				} else {
					alert("请更换邮箱")
				}
			})
		</script>
	</body>

</html>